#ifndef __RENDER_OBJECT__
#define __RENDER_OBJECT__

#include "Framework.hpp"
#include "Shader.hpp"
#include <string>
#include <vector>
#include <map>


class RenderObject {
 public:
  enum VertexAttrib{
    VertexElementIndex=0,
    VertexPosition,
    VertexNormal,
    VertexTexture,
    VertexTangent, 
    VertexBitangent,
    NumVertexAttrib
  };



  RenderObject(const string fn, unsigned int flags=(
						    aiProcess_CalcTangentSpace |
						    aiProcess_Triangulate |
						    aiProcess_JoinIdenticalVertices),
	       GLenum ptype = GL_TRIANGLES);
  ~RenderObject();


  /*override imported properties*/
  void setDiffuse(aiColor3D c){diff = c; diffOver = true;}
  void setSpecular(aiColor3D c){spec = c;specOver = true;}
  void setAmbient(aiColor3D c){ambi = c; ambiOver = true;}
  void setDiffuseTex(GLuint d){ diffTex = d; diffTexOver = true;}

  /*recall material property*/
  void Diffuse(aiMaterial* mat, aiColor3D &c);
  void Specular(aiMaterial* mat, aiColor3D &c);
  void Ambient(aiMaterial* mat, aiColor3D &c);
  void BindDiffuseTex(int m);

  void printSceneStats();
  float* getLocation(){return location;} 
 
  virtual void Render(Shader* s);

  void scale(float s){
    size= s;
  }
  void translate(float x, float y, float z){
    location[0] = x;
    location[1] = y;
    location[2] = z;
  }
  float* getTranslation(){return location;}

 protected:
  virtual void drawNode(aiNode * n);
  void setMaterial(int m);
  void drawMesh(int m);
  void initTextures();
  void initVertices();
  
 public:
  Assimp::Importer importer;
  const aiScene* scene;
  unsigned int** indexBuffer;
  int* indexSize;
  
  map<int, sf::Image*> diffuseMap;
  map<int, sf::Image*> specularMap;
  map<int, sf::Image*> normalMap;
  
  string filename;




 protected:
  /*additional transformation*/
  float location[3];
  float size;

  /*import overrides*/
  bool diffOver;
  bool specOver;
  bool ambiOver;
  bool diffTexOver;
  aiColor3D diff;
  aiColor3D spec;
  aiColor3D ambi;
  GLuint diffTex;  
  

  Shader* shader;
    
  /*drawing*/
  vector<GLuint> vobIDs;
  GLenum primitiveType;
  int primitiveSize;


};

#endif
